﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using MockupDesigner.AppItems.Documents;
using System.Windows.Media;

namespace MockupDesigner.AppItems.Commands
{
    public class PrintCommand : ICommand
    {

        public CommandType CommandType
        {
            get { return CommandType.NonDisturbing; }
        }

        public void Execute(object target, params object[] parameters)
        {
            if (!(target is Window1))
            {
                throw new InvalidCastException("The target must be the Window");
            }
            if (parameters.Length == 0 || !(parameters[0] is Document))
            {
                throw new InvalidCastException("The parameter must be a Document");
            }
            Document document = (Document)parameters[0];
            document.DesignerCanvas.SelectionService.ClearSelection();

            PrintDialog printDialog = new PrintDialog();

            if (true == printDialog.ShowDialog())
            {
                Brush originalBG = document.DesignerCanvas.Background;
                document.DesignerCanvas.Background = Brushes.White;
                document.DesignerCanvas.SelectionService.ClearSelection();
                document.DesignerCanvas.UpdateLayout();
                printDialog.PrintVisual(document.DesignerCanvas, document.DocumentName);
                document.DesignerCanvas.Background = originalBG;
            }
        }


        public void Redo()
        {
            // Nothing to do
        }

        public void Undo()
        {
            // Nothing to do
        }

    }
}
